<template>
    <div class="addressPage">
        <PageHeader :lang="lang"></PageHeader>
        <!--资产总览-->
        <div class="pageBody" id="pageBody">
          <!-- 左侧部分 -->
            <pageLeftMenu></pageLeftMenu>
          <!-- 右侧部分 -->
            <div class="pageMain">
                <div class="mainHead">
                  <h3 class="mainTitle">
                      {{lang['total assets replacement']}}：
                      <span v-show="langKey === 'zh-CN'">CNY <b>¥</b>{{totalNum(tota.TotalUSD, exchangeRate, 2)| currency('USD', '')}}</span>
                      <span v-show="langKey === 'vi'" class="hidden-h5">VND <b>₫</b>{{totalNum(tota.TotalUSD, exchangeRate, 2)| currency('USD', '')}}</span>
                      <span class="hidden-h5">USDT <b>$</b>{{tota.TotalUSD | currency('USD', '')}}</span>
                  </h3>
                </div>

                <div class="Address_Added">
                  <div class="content">
                   <dl>
                     <dt>
                       <p class="title">{{lang['currency surname']}}</p>
                       <!-- <span>请选择</span>
                     -->
                    <select class="teaxt" v-model="coinId">
                      <option value="">{{lang['please choose']}}</option>
                      <option v-for="item in bizhong" :value="item.ID">{{item.Code}}</option>
                    </select>
                   </dt>
                   <dd>
                     <p class="title">{{lang['currency address']}}</p>
                     <input type="text" v-model="coinAddress" :placeholder="lang['please enter the coin address']" class="tibidizhi"></dd>
                   <dd>
                     <p class="title" >{{lang['remarks']}}</p>
                     <input type="text" class="beizhu" maxlength="20" v-model="remark" :placeholder="lang['please memo information']"></dd>
                   </dl>
                </div>
                <button type="button" class="sumbitBox" @click="submitAdd">{{lang['add']}}</button>
              <!-- 提币安全验证 提币第二步-->

                <SwModal modalClass="userModal" :isShow.sync="isShowPINBox" :isCloseOnClickBg="true">
                  <div class="PINBox">
                    <div class="title">{{lang['safety verification']}}
                      <a class="close_safety" @click="close($event)"><img src="../../assets/images/page/asset_03.png"></a>
                    </div>
                    <ul>
                      <li>
                          <p class="text">{{lang['basic_capitalPassword']}}</p>
                          <p class="inpu">
                            <input type="password" class="password" :placeholder="lang['pleaseEnterAFundPassword']" maxlength="6" minlength="6" v-model="assetPassword">
                          </p>
                      </li>
                      <li>
                          <button type="button" class="subitmBox" @click="subitmBox($event)">{{lang['determineBth']}}</button>
                          <router-link class="forgetPIN" :to="{path:'/safety', query:{isShowForgerPin: 'true'}}" v-html="lang['forget fund password']"></router-link>
                      </li>
                    </ul>
                  </div>
                </SwModal>
              </div>
              <div class="Fetch_pen">
                  <h2 class="tit">{{lang['coin list']}}</h2>
                   <dl class="dlHead">
                     <dd>
                       <div class="AddedSelect AddedSelect2">
                         <select @change="CurrencyID" v-model="listCoinId">
                           <option value="">{{lang['currency surname']}}</option>
                           <option v-for="item in bizhong" :value="item.ID">{{item.Code}}</option>
                         </select>
                       </div>
                     </dd>
                     <dd>{{lang['currency address']}}</dd>
                     <dd>{{lang['remarks']}}</dd>
                     <dd>{{lang['operate']}}</dd>
                   </dl>

                  <ul>
                    <li class="dlListss" v-for="(item, index) in list" v-show="dizhishow">
                        <dd>{{item.Coin.Code}}</dd>
                        <dd>{{item.Address}}</dd>
                        <dd>{{item.Remark}}</dd>
                        <dd>
                          <button class="colorRed" :value="item.ID" @click="shandilist($event, index)">{{lang['delete']}}</button>
                        </dd>
                    </li>
                  </ul>
              </div>
              <SwPaging :total="total" :pageSize="pageSize" :pageIndex="pageIndex"  :pageRange="pageRange" :lang="lang" @jumpPage="jumpPage"></SwPaging>
            </div>
        </div>
        <!--资产总览-->
        <PageFooter2 :lang="lang" :langKey="langKey"></PageFooter2>
    </div>
</template>

<script>
import commonMixins from '@/mixins/common.js'
import mixins from './mixins.js'
import SwModal from '@/components/SwModal'
import ModalApi from '@/components/SwModal/api.js'
import SwPaging from '@/components/SwPaging/index.vue'
import pageLeftMenu from './components/pageLeftMenu.vue'
import rules from '@/utils/rules.js'
import Decimal from '@/libs/decimal.min.js'
import commonFilter from '@/filters/common.js'

export default {
  mixins: [commonMixins, mixins],
  data () {
    return {
      list: [],
      isShowPINBox: false,
      dizhi: '',
      dizhishow: true,
      coinAddress: '',
      bizhong: '',
      coinId: '',
      remark: '',
      listCoinId: '',
      pageIndex: 1, // 当前页
      pageSize: 5, // 每页多少条
      pageRange: 7, // 页码条范围，例如8就是显示1-7的页码条
      total: 0,
      assetPassword: '',
      tota: {
        TotalUSD: 0
      }
    }
  },
  components: {
    SwModal,
    ModalApi,
    SwPaging,
    pageLeftMenu
  },
  methods: {
    totalNum (value, rate, pre) {
      let number = new Decimal(value || 0)
      number = number.mul(rate).toFixed(10)
      return commonFilter.fillDecimal(commonFilter.currency(number, 'USD', '', pre), pre)
    },
    CurrencyID () {
      this.pageIndex = 1
      this.tibilist()
    },
    shandilist (e, index) {
      if (index !== '') {
        let confirm = ModalApi.confirm({
          isShowCloseBtn: true,
          isCloseOnClickBg: true,
          modalClass: 'userModal',
          title: 'point out',
          content: 'delete the address coin',
          okText: 'delete',
          noText: '',
          isShowBg: true,
          ok: () => {
            let idd = e.target.value
            this.$http.post('CoinUserAddress/Delete', {
              id: idd
            }, {
              modalOptions: {
                modalClass: 'userModal'
              }
            })
            .then((res) => {
              if (res.StatusCode === '200') {
                this.list.splice(index, 1)
                confirm.close()
                this.tibilist(this.list.length === 0 && this.pageIndex !== 1 ? this.pageIndex - 1 : this.pageIndex)
              }
            })
          },
          no: () => {
            confirm.close()
          }
        })
      }
    },
    submitAdd (e) {
      this.assetPassword = ''
      if (!rules.required.test(this.coinId)) {
        ModalApi.message(this.lang['41011'], null, null, 'userModal')
      } else if (!rules.required.test(this.coinAddress)) {
        ModalApi.message(this.lang['please enter the coin address'], null, null, 'userModal')
      } else {
        this.isShowPINBox = !this.isShowPINBox
      }
    },
    close (e) {
      this.isShowPINBox = false
    },
    subitmBox (e) {
      if (!this.assetPassword) {
        ModalApi.message(this.lang['PleaseEnterPasswordNumber'], null, null, 'userModal')
      } else {
        this.$http.post('CoinUserAddress/Add', {
          'TransactionPassword': this.assetPassword,
          'CoinID': this.coinId,
          'Remark': this.remark,
          'Address': this.coinAddress,
          'ClientType': 0
        }, {
          modalOptions: {
            modalClass: 'userModal'
          }
        })
        .then((res) => {
          if (res.StatusCode === '200') {
            this.showTip()
            this.isShowPINBox = false
            this.coinAddress = ''
            this.coinId = ''
            this.remark = ''
            this.tibilist(1)
          }
        })
      }
    },
    showTip () {
      ModalApi.message(this.lang['add coin address successful'], null, null, 'userModal')
    },
    TradeVariety () {
      this.$http.get('TradeVariety/GetCoinTradeVarietyList', {
      }, {
        modalOptions: {
          modalClass: 'userModal'
        }
      })
      .then((res) => {
        this.bizhong = res.Data
      })
    },
    tibilist (no) {
      this.pageIndex = no || this.pageIndex
      this.$http.post('CoinUserAddress/GetCoinUserAddress', {
        CoinID: this.listCoinId,
        Remark: '',
        CoinAddress: '',
        PageSize: this.pageSize,
        PageIndex: this.pageIndex,
        ClientType: 0
      }, {
        modalOptions: {
          modalClass: 'userModal'
        }
      })
      .then((res) => {
        this.list = res.Data
        this.total = res.TotalItem
      })
    },
    jumpPage (no) {
      this.tibilist(no)
    },
    getlists () {
      this.$http.post('CustomerAssets/GetAssets', {
      }, {
        modalOptions: {
          modalClass: 'userModal'
        }
      })
      .then((res) => {
        if (res.Status === true) {
          this.tota = res.Data
        } else {

        }
      })
    }
  },
  mounted () {
    this.TradeVariety()
    this.tibilist()
    this.exchangeCurrency()
    this.getlists()
  }
}
</script>

<style lang="less">
.userModal{
  .head{
    text-align: center;
  }
  .sw-confirm{
    text-align: center;
  }
}
.addressPage {
  font-weight: 100;
  input::-webkit-input-placeholder {
    color: #bbb;
  }
  .mainHead{
    height: 49px;
    line-height: 49px;
    color: #c4c7c9;
    h3{
    font-weight: 100;
    }
    span{
      margin-right: 30px;
      letter-spacing:1.5px;
      font-weight: 100;
      b{
        font-weight: normal;
        font-family: '黑体';
      }
    }
  }

  .Fetch_pen {
    position: relative;
  }
  .SwPaging {
    padding: 5px 0;
    text-align: center;
    margin: 0 auto;
    margin-top: 25px;
  }
  .passowrd div {
    color: #d37070;
  }
  .Address_Added {
    background-color: #191E2A;
    padding: 27px 15px;
  }
  .Address_Added dl {
    display: flex;
    flex-wrap: wrap;
  }
  .Address_Added dl .title {
    line-height: 40px;
    color: #c4c7c9;
  }
  .Address_Added dt {
    padding: 0 1%
  }
  .Address_Added dd {
    padding: 0 1%
  }
  .Address_Added dd input {
    color: #c4c7c9;
    font-size: 12px;
    height: 40px;
    background: #2A3440;
    border-radius: 2px;
    width: 100%;
    padding: 0 5px;
  }
  .Address_Added .tibidizhi, .Address_Added .beizhu{
    width: 300px;
  }
  .Address_Added .sumbitBox {
    display: block;
    width: 260px;
    height: 40px;
    border-radius: 2px;
    background: #3782FF;
    font-size: 12px;
    color: white;
    margin: 36px auto 0;
  }

  .Fetch_pen {
    padding-top: 25px;
    color: #c4c7c9;
  }
  .Fetch_pen .tit {
    font-size: 14px;
    padding-bottom: 15px;
    color: #c4c7c9;
  }
  .Fetch_pen dl {
    padding: 0 15px;
    color: #c4c7c9;
  }
  .Fetch_pen .dlHead {
    height: 50px;
    line-height: 50px;
    font-size: 14px;
    background: #191E2A;
  } // .Fetch_pen .dlHead dd{ height: 50px;}
  .Fetch_pen dd {
    font-size: 14px;
    float: left;
    width: 42%;
    color: #c4c7c9;
  }
  .Fetch_pen dd:nth-of-type(3) {
    width: 30%
  }
  .Fetch_pen dd:first-child {
    float: left;
    width: 20%;
  }
  .Fetch_pen dd:last-child {
    float: right;
    width: 8%;
    text-align: right
  }
  .Fetch_pen .dlListss {
    position: relative;
    line-height: 48px;
    height: 48px;
    color: #191f2b;
    background: #181A23;
  }
  // .Fetch_pen .dlListss:hover{
  //   background: #2A3440;
  // }
  .Fetch_pen .dlListss dd {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .Fetch_pen .remark{
    word-wrap: break-word;
    background: #2A3440;
    box-shadow: 0 2px 4px 0 rgba(0,0,0,0.50);
    border-radius: 2px;
    position: absolute;
    top: 50px;
    font-size: 10px;
    line-height: 20px;
    padding: 10px;
    right: 0;
    width: 300px;
  }
  .Fetch_pen .remark b{
    position: absolute;
    top: -8px;
    right: 0;
    left: 0;
    margin: 0 auto;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 8px solid #2A3440;
  }
  .Fetch_pen select {
    color: #c4c7c9;
  }
  .Fetch_pen select option{
    background: #191E2A;
  }
  .Fetch_pen .dlListss img {
    vertical-align: middle;
    padding-right: 5px;
  }
  .Fetch_pen .dlListss .colorRed {
    color: #f84164;
    background: none;
    border: none
  }
  /*.Fetch_pen  ul li {background: #dfdfdf}*/
  .Fetch_pen ul li {
    padding: 0 15px;
  }
  /*下拉样式*/
  .AddedSelect {
    position: relative;
  }
  .teaxt {
    display: block;
    outline: none;
    border: none;
    text-align: center;
    background-color: #2A3440;
    background-position: 90% center;
    color: #c4c7c9;
    height: 40px;
    padding: 0 30px 0 10px;
    line-height: 40px;
  }
  .teaxt::-webkit-scrollbar {
    display: none;
  }
  .teaxt option {
    background: #2A3440;
    text-align: center;
  }
  .teaxt option:hover {
    background: #3782FF;
  }
  .AddedSelect .teaxt img {
    float: right;
    padding-top: 10px;
  }
  .AddedSelect ul {
    position: absolute;
    width: 100%;
    top: 35px;
    border-bottom-right-radius: 3px;
    border-bottom-left-radius: 3px;
    border: solid 1px #213763;
    box-sizing: border-box;
    padding: 5px 0;
    display: none;
  }
  .AddedSelect ul:hover {
    background: #fff
  }
  .AddedSelect ul li {
    line-height: 22px;
    padding: 0 10px;
    color: #191f2b;
    cursor: pointer;
  }
  .AddedSelect ul li.active {
    background: url(../../assets/images/page/asset_05.png)no-repeat 90% center;
  }
  .AddedSelect:hover .teaxt img {
    transform: rotate(180deg);
    padding-top: 0;
    padding-bottom: 10px;
  }
  .AddedSelect:hover ul {
    display: block;
  }

  .AddedSelect2 .teaxt {
    border: none;
  }
  .AddedSelect2 ul {
    top: 34px;
    background: #d5d5d5;
    border-radius: 3px;
    border: none;
  }
  .AddedSelect2 ul:after {
    content: "";
    width: 0;
    height: 0;
    border-bottom: solid 5px #d5d5d5;
    border-left: solid 5px Transparent;
    border-right: solid 5px Transparent;
    position: absolute;
    top: -5px;
    left: 30px;
  }
  .AddedSelect2 ul li {
    color: #fff;
  }
  .AddedSelect2 ul li.active {
    background: url(../../assets/images/page/asset_06.png)no-repeat 90% center;
  }
  .AddedSelect ul li:hover {
    color: #fff;
    background: #213763;
  }
}

.PINBox {
  width: 441px;
  background: #1A1F2B;
  border-radius: 5px;
  position: fixed;
  left: 56%;
  color: #fff;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 0 36px;

  .title {
    height: 28px;
    line-height: 28px;
    text-align: center;
    padding: 26px 0 16px;
    img {
      vertical-align: middle;
      text-align: center;
    }
    .close_safety {
      float: right;
    }
  }

  li {
    text-align: center;
    position: relative;
  .text {
    text-align: left;
    padding:0 10px;
  }
  .inpu {
    position: relative;
      input {
        font-weight: lighter;
        box-sizing: border-box;
        line-height: 40px;
        height: 40px;
        width: 100%;
        background: #2A3440;
        border-radius: 2px;
        color: #fff;
        padding: 0 10px;
      }
      input[disabled='disabled'] {
        background: #fafdff;
      }
    }
    .subitmBox {
      font-size: 12px;
      font-weight: lighter;
      display: inline-block;
      height: 40px;
      line-height: 40px;
      border-radius: 2px;
      width: 220px;
      background: #3782FF;
      color: #fff;
      margin: 36px auto;
    }
    .shutdown{
      font-weight: lighter;
      color: #fff;
      position: absolute;
      right: 0;
      top: 5px;
      font-size: 12px;
    }
  }
  a.forgetPIN {
    position: absolute;
    color: #fff;
    font-size: 12px;
    top:5px;
    right: 0;

    font{
      color: #3782FF;
    }
  }
}
@media screen and (max-width: 1100px){
  .hidden-h5 {
    display: none;
  }
  .addressPage .Address_Added {
    .content {
      display: flex;
      justify-content: center;
    }

    dl {
      width: 500px;
    }
    dd:nth-child(2) {
      margin-left: 22px;
    }
    .tibidizhi {
      width: 350px;
    }
    .beizhu {
      width: 465px;
    }
  }
}
</style>
